From c4e6e3c6106518f86e2d0a3062c1bbca152d12ea Mon Sep 17 00:00:00 2001 From: Hollis Blanchard Date: Fri, 9 Feb 2007 14:43:21 -0600 Subject: [PATCH] [POWERPC][XEN] strlcpy() fallout. - Implement strlcpy() for the dom0 firmware. - Remove strncpy() from dom0 firmware. - Correct buffer length in device tree copying. Signed-off-by: Hollis Blanchard --- xen/arch/powerpc/of-devtree.c | 2 +- xen/arch/powerpc/of_handler/Makefile | 2 +- .../powerpc/of_handler/{strncpy.c => strlcpy.c} | 16 ++++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) rename xen/arch/powerpc/of_handler/{strncpy.c => strlcpy.c} (84%) diff --git a/xen/arch/powerpc/of-devtree.c b/xen/arch/powerpc/of-devtree.c index 9296a4505a..c437ef4569 100644 --- a/xen/arch/powerpc/of-devtree.c +++ b/xen/arch/powerpc/of-devtree.c @@ -358,7 +358,7 @@ static ofdn_t ofd_node_create( n->on_io = 0; n->on_pathlen = pathlen; n->on_last = ofd_pathsplit_left(path, '/', pathlen); - strlcpy(n->on_path, path, pathlen); + strlcpy(n->on_path, path, pathlen + 1); return pos; } diff --git a/xen/arch/powerpc/of_handler/Makefile b/xen/arch/powerpc/of_handler/Makefile index 4954e374de..3b2dfdbe10 100644 --- a/xen/arch/powerpc/of_handler/Makefile +++ b/xen/arch/powerpc/of_handler/Makefile @@ -27,5 +27,5 @@ obj-y += snprintf.o obj-y += strcmp.o obj-y += strlen.o obj-y += strncmp.o -obj-y += strncpy.o +obj-y += strlcpy.o obj-y += strnlen.o diff --git a/xen/arch/powerpc/of_handler/strncpy.c b/xen/arch/powerpc/of_handler/strlcpy.c similarity index 84% rename from xen/arch/powerpc/of_handler/strncpy.c rename to xen/arch/powerpc/of_handler/strlcpy.c index 76c5c7182a..02f33e8d62 100644 --- a/xen/arch/powerpc/of_handler/strncpy.c +++ b/xen/arch/powerpc/of_handler/strlcpy.c @@ -13,16 +13,18 @@ * along with this program; if not, write to the Free Software * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * - * Copyright (C) IBM Corp. 2005 + * Copyright IBM Corp. 2005, 2007 * * Authors: Jimi Xenidis + * Hollis Blanchard */ #include -char * -strncpy(char *dest, const char *src, size_t n) +size_t +strlcpy(char *dest, const char *src, size_t n) { + size_t ret; char *dp; /* cases to consider: @@ -34,7 +36,7 @@ strncpy(char *dest, const char *src, size_t n) */ if (n <= 0) { - return dest; + return 0; } dp = dest; @@ -43,12 +45,14 @@ strncpy(char *dest, const char *src, size_t n) *dp++ = *src; --n; ++src; - } while ((*src != '\0') && (n > 0)); + } while ((*src != '\0') && (n > 1)); + + ret = n; /* clear remainder of buffer (if any); ANSI semantics */ while (n > 0) { *dp++ = '\0'; --n; } - return dest; + return ret; } -- 2.30.2